﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;


namespace IHISCETeim.Web.MachineSys.WModel
{
    public partial class WOWORTaskAdd : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "WOWORTaskAdd";
            }
        }
        #region 属性 (查询条件)


        protected int PID
        {
            get
            {
                return GetRequestValue<int>("PID", 0);

            }
        }

        private OProjectInfo _pObj = null;
        protected OProjectInfo pObj
        {
            get
            {
                if (_pObj == null)
                    _pObj = OProjectController.GetById(PID);
                return _pObj;
            }
        }

        protected string GetProject()
        {
            DataTable dt = OProjectController.GetByIsComplete();
            dt=   dt.Select(" PName not like 'QT%'").CopyToDataTable();
            string optiontemp = "<option value='{0}' {2}>{1}[{5}{3}-{5}{4}]</option>";
            string rhtml = "";
            rhtml += string.Format(optiontemp, "0", "请选择", PID == 0 ? "selected" : "","","","");
            foreach (DataRow dr in dt.Rows)
            {
                rhtml += string.Format(optiontemp, dr["PID"], dr["PName"], Convert.ToInt32(dr["PID"].ToString()) == PID ? "selected" : "", dr["StartNum"], dr["EndNum"], dr["TypeSuff"]);
            }
            return rhtml;

        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "search")
            {
                 DataBind();
            }
            if (GetRequestValue<string>("ajaxmethod", "") == "addtask")
            {
                addtask();
            }
        }
        /// <summary>
        /// 是否已发布过
        /// </summary>
        protected bool Sended = false;
        protected void DataBind()
        {
            if (PID == 0)
                return;
            this.rpMenu.DataSource = WOWORTaskController.GetTask(pObj.MachineType);
            this.rpMenu.DataBind();

            Sended= WOWORTaskController.CheckOWORTaskByPName(pObj.PName)>0;
          
        }

        protected void addtask() {
            string RealName=base.User.RealName;
            string Pname=pObj.PName;
            string docnums=GetRequestValue<string>("docnum","");
            string SendQtys = GetRequestValue<string>("SendQty", "");


            int r= WOWORTaskController.AddWoroTask(RealName, Pname, docnums, SendQtys);
            if (r <= 0)
                AlertJson("对不起，下发生产任务失败");
            else
                SuccessJson("成功下发生产任务");

        }
    }
}